﻿Imports System.Data.SqlClient

Public Class clsUniformes
    Private mintidUniforme As Integer
    Private mdatFecha As Date
    Private mstrTallaPantalon As String
    Private mintCantidadPantalon As Integer
    Private mstrTallaCamisa As String
    Private mintCantidadCamisa As Integer
    Private mstrTallaGorro As String
    Private mintCantidadGorro As Integer
    Private mintidEmpleado As Integer
    Public Property idUniforme() As Integer
        Get
            Return mintidUniforme
        End Get
        Set(ByVal value As Integer)
            mintidUniforme = value
        End Set
    End Property
    Public Property Fecha() As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property

    Public Property TallaPantalon() As String
        Get
            Return mstrTallaPantalon
        End Get
        Set(ByVal value As String)
            mstrTallaPantalon = value
        End Set
    End Property
    Public Property CantidadPantalon() As Integer
        Get
            Return mintCantidadPantalon
        End Get
        Set(ByVal value As Integer)
            mintCantidadPantalon = value
        End Set
    End Property
    Public Property TallaCamisa() As String
        Get
            Return mstrTallaCamisa
        End Get
        Set(ByVal value As String)
            mstrTallaCamisa = value
        End Set
    End Property
    Public Property CantidadCamisa() As Integer
        Get
            Return mintCantidadCamisa
        End Get
        Set(ByVal value As Integer)
            mintCantidadCamisa = value
        End Set
    End Property
    Public Property TallaGorro() As String
        Get
            Return mstrTallaGorro
        End Get
        Set(ByVal value As String)
            mstrTallaGorro = value
        End Set
    End Property
    Public Property CantidadGorro() As Integer
        Get
            Return mintCantidadGorro
        End Get
        Set(ByVal value As Integer)
            mintCantidadGorro = value
        End Set
    End Property
    Public Property idEpleado() As Integer
        Get
            Return mintidEmpleado
        End Get
        Set(ByVal value As Integer)
            mintidEmpleado = value
        End Set
    End Property
    Public Sub New()
        mintidUniforme = 0
        mdatFecha = Now()
        mstrTallaPantalon = ""
        mintCantidadPantalon = 0
        mstrTallaCamisa = ""
        mintCantidadCamisa = 0
        mstrTallaGorro = ""
        mintCantidadGorro = 0
        mintidEmpleado = 0
    End Sub
    Public Sub Guardar()

        If idUniforme = 0 Then
            Exit Sub
        End If

        Dim intRetVal As Integer

        intRetVal = BuscarIntDatoCitra("Uniformes", "iduniforme", "iduniforme=" & idUniforme)

        If intRetVal = 0 Then
            Insertar()
        Else
            Actualizar()

        End If

    End Sub
    Public Sub Borrar()
        Call SetSqlCitra("Delete From Uniformes Where iduniforme = " & idUniforme)

    End Sub
    Public Sub Buscar()
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Uniformes " & _
        " WHERE iduniforme=" & idUniforme

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        If rdBuscar.Read() Then
            mintidUniforme = rdBuscar("id")
            mdatFecha = rdBuscar("fecha")
            mstrTallaPantalon = rdBuscar("tallapantalon").ToString.Trim
            mintCantidadPantalon = rdBuscar("cantidadpantalon")
            mstrTallaCamisa = rdBuscar("tallacamisa").ToString.Trim
            mintCantidadCamisa = rdBuscar("cantidadcamisa")
            mstrTallaGorro = rdBuscar("tallagorro").ToString.Trim
            mintCantidadGorro = rdBuscar("cantidadgorro")
            mintidEmpleado = rdBuscar("idempleado")
        Else
            mintidUniforme = 0
            mdatFecha = Now()
            mstrTallaPantalon = ""
            mintCantidadPantalon = 0
            mstrTallaCamisa = ""
            mintCantidadCamisa = 0
            mstrTallaGorro = ""
            mintCantidadGorro = 0
            mintidEmpleado = 0
        End If

        rdBuscar.Close()
        cnConn.Close()


    End Sub
    Public Sub Insertar()

        Dim sql As String = "Insert Into Uniformes (" & _
                            "IdUniforme," & _
                            "IdEmpleado," & _
                            "Fecha," & _
                            "TallaPantalon," & _
                            "CantidadPantalon," & _
                            "TallaCamisa," & _
                            "CantidadCamisa," & _
                            "TallaGorro," & _
                            "CantidadGorro)" & _
                            "VALUES (" & _
                            "@IdUniforme," & _
                            "@IdEmpleado," & _
                            "@Fecha," & _
                            "substring(@TallaPantalon,1,10)," & _
                            "@CantidadPantalon," & _
                            "substring(@TallaCamisa,1,10)," & _
                            "@CantidadCamisa," & _
                            "substring(@TallaGorro,1,10)," & _
                            "@CantidadGorro)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdUniforme", mintidUniforme)
        Command.Parameters.AddWithValue("IdEmpleado", mintidEmpleado)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("TallaPantalon", mstrTallaPantalon)
        Command.Parameters.AddWithValue("CantidadPantalon", mintCantidadPantalon)
        Command.Parameters.AddWithValue("TallaCamisa", mstrTallaCamisa)
        Command.Parameters.AddWithValue("CantidadCamisa", mintCantidadCamisa)
        Command.Parameters.AddWithValue("TallaGorro", mstrTallaGorro)
        Command.Parameters.AddWithValue("CantidadGorro", mintCantidadGorro)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Actualizar()
         Dim strSqlQry As String
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = NominasConnection

        strSqlQry = "Update Uniformes Set " & _
                    " Fecha=@Fecha, " & _
                    " TallaPantalon=substring(@TallaPantalon,1,10), " & _
                    " CantidadPantalon=@CantidadPantalon, " & _
                    " TallaCamisa=substring(@TallaCamisa,1,10), " & _
                    " CantidadCamisa=@CantidadCamisa, " & _
                    " TallaGorro=substring(@TallaGorro,1,10), " & _
                    " CantidadGorro=@CantidadGorro " & _
                    " where IdUniforme=@IdUniforme"

        Dim Command As New SqlCommand(strSqlQry, cnConn)
        Command.Parameters.AddWithValue("IdUniforme", mintidUniforme)
        Command.Parameters.AddWithValue("IdEmpleado", mintidEmpleado)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("TallaPantalon", mstrTallaPantalon)
        Command.Parameters.AddWithValue("CantidadPantalon", mintCantidadPantalon)
        Command.Parameters.AddWithValue("TallaCamisa", mstrTallaCamisa)
        Command.Parameters.AddWithValue("CantidadCamisa", mintCantidadCamisa)
        Command.Parameters.AddWithValue("TallaGorro", mstrTallaGorro)
        Command.Parameters.AddWithValue("CantidadGorro", mintCantidadGorro)


        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar los datos en ContPAQ I Nominas", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub

End Class
